home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 16
/
CU Amiga Magazine's Super CD-ROM 16 (1997-10-16)(EMAP Images)(GB)[!][issue 1997-11].iso
/
CUCD
/
Graphics
/
Ghostscript
/
source
/
gs_fform.ps
< prev
next >
Wrap
Text File
|
1996-09-05
|
4KB
|
111 lines
% Copyright (C) 1995, 1996 Aladdin Enterprises. All rights reserved.
%
% This file is part of Aladdin Ghostscript.
%
% Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author
% or distributor accepts any responsibility for the consequences of using it,
% or for whether it serves any particular purpose or works at all, unless he
% or she says so in writing. Refer to the Aladdin Ghostscript Free Public
% License (the "License") for full details.
%
% Every copy of Aladdin Ghostscript must include a copy of the License,
% normally in a plain ASCII text file named PUBLIC. The License grants you
% the right to copy, modify and redistribute Aladdin Ghostscript, but only
% under certain conditions described in the License. Among other things, the
% License requires that the copyright notice and this notice be preserved on
% all copies.
% gs_fform.ps
% Monochrome Form caching implemented in PostScript.
% This implementation is pretty unreasonable:
% - It doesn't remember transparent pixels.
% - It reduces everything to black and white.
% - It doesn't handle halftone or Pattern phasing.
% However, it's good enough to produce some useful output.
% In order to prevent restore from clearing the cache, we explicitly
% push the cache entries on the stack before a restore and reinstall them.
/formcachedict 20 dict def
currentglobal true setglobal
/restore
{ mark formcachedict { } forall
counttomark 1 add index { restore } .internalstopped
{ cleartomark restore }
{ counttomark 2 idiv { formcachedict 3 1 roll put } repeat pop pop }
ifelse
} bind odef
/.form.buffer 65000 string def
/execform
{ dup /Implementation known not
{ dup /FormType get 1 ne { /rangecheck signalerror } if
formcachedict 1 index .knownget not
{ currentglobal true setglobal
% Stack: form global
10 dict
dup /ImageType 1 put
dup /ImageMatrix [0 0 0 0 0 0] put
dup /DataSource
{ % Stack: y (impl is on dict stack)
Height 1 index sub
//.form.buffer length Width 7 add 8 idiv idiv .min
1 index add exch
Device exch //.form.buffer copyscanlines
}
put
dup /BitsPerComponent 1 put
dup /Decode [0 1] put
dup /Device null put
% Stack: form global impl
formcachedict 3 index 2 index put
exch setglobal
}
if 1 index /Implementation 3 -1 roll put
}
if
gsave dup /Matrix get concat
dup /Implementation get
% Check whether we can use the cached value.
% Stack: form implementation
dup /ImageMatrix get matrix currentmatrix
true 0 1 3
{ % Stack: form impl cachemat curmat true index
3 index 1 index get exch 3 index exch get ne { pop false exit } if
}
for % Stack: form impl cachemat curmat valid
exch pop exch pop not
{ % Cache is invalid. Execute the Form and save the bits.
gsave begin
currentglobal exch true setglobal
ImageMatrix currentmatrix pop
dup /BBox get aload pop
exch 3 index sub exch 2 index sub rectclip
% Make the cache device.
clippath gsave matrix setmatrix pathbbox grestore
% We now have the bounding box in device space.
2 { 4 -1 roll floor cvi } repeat
2 { 4 -1 roll ceiling cvi } repeat
2 index sub /Height exch def
2 index sub /Width exch def
ImageMatrix aload pop
exch 7 index sub exch 6 index sub
6 array astore
3 1 roll pop pop
dup ImageMatrix copy pop
Width Height <00 ff> makeimagedevice
/Device 1 index def
nulldevice setdevice initgraphics
exch setglobal
dup dup /PaintProc get exec
nulldevice grestore currentdict end
}
if
% Now paint the bits.
% Stack: form implementation
/DeviceGray setcolorspace dup begin 0 exch image end pop
pop grestore
} odef
setglobal